<template>
	<view class="content">
		<u-navbar bgColor="#fff" :placeholder="true" :fixed="true" @leftClick="$back" title="dream约文" titleStyle="{'color': '#000'}">
			
		</u-navbar>
		<view class="baibox">
			<view class="baili">
				<view class="left">
					<view class="title">
						约文标题
					</view>
					<input type="text" class="put" placeholder="请输入" v-model="form.title">
				</view>
			</view>
					
			<picker class="baiput"  @change="leiChange" :value="lei" :range="leiList" range-key="name">
				<view class="title">
					类型设置
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
				{{leiList[lei].name}}
			</picker>
				
			<view class="baili" @click="show = true">
				<view class="left">
					<view class="title">
						价格设置
					</view>
					<view class="txt">
						{{form.price?form.price:'请输入金额'}}
					</view>
				</view>
				<view class="left">
					<view class="title">
						字数设置
					</view>
					<view class="txt">
						{{form.word_count?form.word_count:array[index]}}
					</view>
				</view>
				<image :src="'/images/rarr.png' | formatImgUrl" class="rarr" mode=""></image>
			</view>

			<view class="baili">
				<view class="left">
					<view class="title">
						起拍单量
					</view>
					<input type="number" class="put" placeholder="请输入起拍单量" maxlength="5" v-model="form.start_shooting">
				</view>
				<view class="desText">{{form.word_count?form.word_count:array[index]}}</view>
			</view>
		</view>
		<view class="ti" @click="submit">
			保存
		</view>

		<u-popup :show="show" mode="center" @close="close" @open="open">
			<view class="mask">
				<view class="jatitle">
					价格设置
				</view>
				<input type="number" class="japut" placeholder="请输入价格(币)" v-model="form.price" maxlength="5">
				<view class="jatitle">
					字数设置
				</view>
				<picker class="japut" @change="bindPickerChange" :value="index" :range="array">
					{{array[index]}}
				</picker>
				<view class="qubox">
					<view class="quli" @click="show = false">
						取消
					</view>
					<view class="que" @click="show = false">
						确定
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				id:0,
				// 字数
				array: this.$db.get('config').word_count_label,
				index: 0,
				// 类型
				leiList: this.$db.get('config').tags.Xslx,
				lei: 0,
				// 起拍
				paiList: '请输入起拍数量',
				// 开关
				value: false,
				// 弹框
				show: false,
				form: {
					title: '',
					row_type: this.$db.get('config').tags.Xslx[0].id,
					price: '',
					word_count: this.$db.get('config').word_count_label[0],
					start_shooting: ''
				},
				isClick: false,
				
			}
		},
		watch: {
			// 'form.price':function(val){
			// 	this.form.price = parseFloat(val).toFixed(2)
			// }
		},
		onShow() {
			console.log("config11")
			if(!this.$db.get('config') || this.$db.get('config') ==null || this.$db.get('config') == undefined){
				console.log("config")
				this.getConfig();
			}
		},
		onLoad(ops) {
			
			if(ops.id){
				this.id = ops.id;
				this.getInfo();
			}
		
		},
		methods: {
	
			getConfig() {
				this.$api.default.request('Common/getConfig').then((res) => {
					if (res.code) {
						this.$db.set('config', res.data)
						
					}
				})
			},
			getInfo() {
				this.$api.default.request('good/info', {
					id: this.id
				}).then((res) => {
					if (res.code) {
						this.form = res.data
						console.log(this.info,77777)
					}
				})
			},
			submit() {
				if (this.isClick) {
					return; // 如果已经禁止点击，则直接返回
				}
				if (this.form.price < 1) {
					this.$common.errorToShow('价格需大于等于1')
					return
				}
				this.isClick = true
				if (this.isClick) {
					this.$api.default.request('good/addGood', this.form, 'POST', false).then((res) => {
						if (res.code == 1) {
							this.$common.successToShow(res.msg, () => {
								this.isClick = false
								uni.navigateBack()
							})
						}
					})
				}

			},

			change(e) {
				this.xuan = !this.xuan
			},

			// 弹框
			open() {

			},

			close() {
				this.show = false
			},
			
			// 字数
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
				this.form.word_count = this.array[e.detail.value]
			},

			// 类型
			leiChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.lei = e.detail.value
				this.form.row_type = this.leiList[e.detail.value].id
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: rgba(242, 245, 242, 1);
	}

	.content {
		padding-top: 20rpx;

		.baibox {
			background-color: #FFFFFF;
			padding: 0 30rpx;
			margin-bottom: 20rpx;
			.baiput{
				position: relative;
				width: 100%;
				height: 120rpx;
				border-bottom: 1px solid rgba(153, 153, 153, 0.1);
				font-size: 24rpx;
				font-weight: normal;
				letter-spacing: 0em;
				color: #3D3D3D;
				line-height: 174rpx;
				.title {
					font-size: 28rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
					position: absolute;
					line-height: 30rpx !important;
					top: 21rpx;
					left: 0;
				}
				.rarr {
					width: 40rpx;
					height: 40rpx;
					position: absolute;
					top: 45rpx;
					right: 0;
				}
			}
			.baili:last-child {
				border: none;
			}
			
			.baili {
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 120rpx;
				border-bottom: 1px solid rgba(153, 153, 153, 0.1);

				.zhan {
					font-size: 28rpx;
					font-weight: bold;
					letter-spacing: 0em;
					color: #3D3D3D;
				}

				.left {
					flex-shrink: 0;

					.title {
						font-size: 28rpx;
						font-weight: bold;
						letter-spacing: 0em;
						color: #3D3D3D;
						padding-bottom: 10rpx;
					}

					.txt {
						font-size: 24rpx;
						font-weight: normal;
						letter-spacing: 0em;
						color: #3D3D3D;
					}

					.put {
						width: 500rpx;
						font-size: 24rpx;
						font-weight: normal;
						letter-spacing: 0em;
						color: #3D3D3D;
					}
				}

				.desText {
					display: flex;
					justify-content: center;
					align-items: flex-end;
					height: 80rpx;
					font-size: 24rpx;
					color: #45C4B0;
				}

				.rarr {
					width: 40rpx;
					height: 40rpx;
					flex-shrink: 0;
				}
			}
		}

		.ti {
			width: 690rpx;
			height: 86rpx;
			border-radius: 8px;
			line-height: 86rpx;
			margin: 0 auto;
			opacity: 1;
			background: #45C4B0;
			font-size: 32rpx;
			font-weight: bold;
			text-align: center;
			letter-spacing: 0em;
			color: #FFFFFF;
		}

		.mask {
			background-color: #FFFFFF;
			width: 500rpx;
			border-radius: 10px;
			padding: 30rpx;

			.jatitle {
				font-size: 28rpx;
				font-weight: bold;
				padding-bottom: 20rpx;
			}

			.japut {
				border-bottom: 1px solid #f2f2f2;
				font-size: 24rpx;
				color: #3D3D3D;
				padding-bottom: 15rpx;
				margin-bottom: 30rpx;
			}

			.qubox {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.quli {
					border-radius: 8px;
					border: 1px solid #eeeeee;
					font-size: 24rpx;
					color: #999999;
					width: 220rpx;
					text-align: center;
					height: 60rpx;
					line-height: 60rpx;
				}

				.que {
					border-radius: 8px;
					border: 1px solid #45C4B0;
					background-color: #45C4B0;
					font-size: 24rpx;
					color: #ffffff;
					text-align: center;
					width: 220rpx;
					height: 60rpx;
					line-height: 60rpx;
				}
			}
		}
	}
</style>